@extends("admin.layout.main")

@section("content")
    <style>
        .ivu-table td.no_padding>.ivu-table-cell{
            padding-left: 0;
            padding-right: 0;
        }
        .ivu-table th.demo-table-info-column{
            background-color: #2db7f5;
            color: white;
        }
    </style>
    <div id="app">

        {{--登记--}}
        <Modal width="30%" title="登记" v-model="regModal"  :mask-closable="false" @on-ok="register">

            <div>
                <span>
                    订单号：
                    <i-input v-model="reg.order_id" long></i-input>
                </span>
                <span>
                    登记人：
                    <i-input v-model="reg.reg_person" long></i-input>
                </span>
                <span>
                    退回物流单号：
                    <i-input v-model="reg.logistics_code" long></i-input>
                </span>
            </div>

        </Modal>

        {{--售卖登记--}}
        <Modal width="30%" title="售卖登记"  :mask-closable="false" v-model="saleModal" @on-ok="saleRegister">

            <div>
                <span>
                    订单ID：
                    <i-input v-model="sale.order_id" disabled long></i-input>
                </span>
                <span>
                    售卖类型：
                    <i-select v-model="sale.sale_type">
                        <i-option value="公司售卖">公司售卖</i-option>
                        <i-option value="退回厂家">退回厂家</i-option>
                    </i-select>
                </span>
            </div>

        </Modal>

        <Row type="flex"  align="middle">
            <i-col span="35" style="margin: 20px ;">

                 <span style="padding-left: 10px">
                     电话：
                      <i-input v-model="search.phone" style="width: 150px"></i-input>
                </span>

                <span style="padding-left: 10px">
                     订单号：
                      <i-input v-model="search.order_id" style="width: 150px"></i-input>
                </span>

                <span style="padding-left: 10px">
                     物流单号：
                      <i-input v-model="search.logistics_code" style="width: 150px"></i-input>
                </span>

                <span style="padding-left: 10px">
                     姓名：
                      <i-input v-model="search.post_receiver" style="width: 150px"></i-input>
                </span>

                 <span style="padding-left: 10px">
                      <i-button type="primary" @click="searchList">查询</i-button>
                </span>

                <span style="padding-left: 10px">
                      <i-button type="primary" @click="regClick">登记</i-button>
                </span>

                <span style="padding-left: 10px">
                        <a :href="combine_link" style="display: inline-block;margin-left: 15px;">统计导出</a>
                </span>

                <span style="padding-left: 10px">
                        <a :href="combine_link1" style="display: inline-block;margin-left: 15px;">原表导出</a>
                </span>



            </i-col>

        </Row>
        <Row type="flex" justify="center" align="middle">
            <i-col span="24" style="margin-top: 20px">
                <i-table ref="selection" border :data="tableData" :columns="tableColumns" stripe
                         style="width: 100% !important;">
                </i-table>
            </i-col>
        </Row>

        <Row type="flex" justify="center" class="code-row-bg">
            <i-col>
                <Page
                        size="small"
                        :total="page.total"
                        :current="page.current"
                        :page-size="page.pageSize"
                        show-total
                        show-elevator
                        @on-change="refundList">

                </Page>
            </i-col>
        </Row>

    </div>
    <script src="/js/layer/layer.js"></script>
    <script src="/js/vue.js"></script>
    <script  src="/js/iview.js"></script>
    <script  src="/js/axios.min.js"></script>
    <script src="/js/common.js"></script>
    <script>
        let vm = new Vue({
            el: '#app',
            data() {
                return {
                    token:'',
                    count_type:'1',
                    tableData: [],
                    page: {
                        total: 0,
                        current: 1,
                        pageSize: 50,
                    },
                    tableColumns: [
                        {
                            title: "店铺",
                            key: "shop_name",
                            className: 'demo-table-info-column',
                        },
                        {
                            title: "订单ID",
                            key: "order_id",
                            className: 'demo-table-info-column',
                        },
                        {
                            title: "产品",
                            key: "origin_prod_name",
                            className: 'demo-table-info-column',
                        },
                        {
                            title: "货号",
                            key: "prod_no",
                            className: 'demo-table-info-column',
                            render: (h, params) => {
                                let row =   params.row;
                                return h('div', [
                                    h('i-input', {
                                        props: {
                                            value:row.prod_no
                                        },
                                        on: {
                                            'on-blur': (event)=>{
                                                this.changeValue('prod_no',params.row,event.target.value);
                                            }
                                        }
                                    }),

                                ]);
                            }
                        },
                        {
                            title: "尺寸",
                            key: "size",
                            className: 'demo-table-info-column',
                            render: (h, params) => {
                                let row =   params.row;
                                return h('div', [
                                    h('i-input', {
                                        props: {
                                            value:row.size
                                        },
                                        on: {
                                            'on-blur': (event)=>{
                                                this.changeValue('size',params.row,event.target.value);
                                            }
                                        }
                                    }),

                                ]);
                            }
                        },
                        {
                            title: "颜色",
                            key: "color",
                            className: 'demo-table-info-column',
                            render: (h, params) => {
                                let row =   params.row;
                                return h('div', [
                                    h('i-input', {
                                        props: {
                                            value:row.color
                                        },
                                        on: {
                                            'on-blur': (event)=>{
                                                this.changeValue('color',params.row,event.target.value);
                                            }
                                        }
                                    }),

                                ]);
                            }
                        },
                        {
                            title: "进货价",
                            key: "cost_price",
                            className: 'demo-table-info-column',
                            render: (h, params) => {
                                let row =   params.row;
                                return h('div', [
                                    h('i-input', {
                                        props: {
                                            value:row.cost_price
                                        },
                                        on: {
                                            'on-blur': (event)=>{
                                                this.changeValue('cost_price',params.row,event.target.value);
                                            }
                                        }
                                    }),

                                ]);
                            }
                        },
                        {
                            title: "售价",
                            key: "combo_amount",
                            className: 'demo-table-info-column'
                        },
                        {
                            title: "姓名",
                            key: "post_receiver",
                            className: 'demo-table-info-column'
                        },
                        {
                            title: "电话",
                            key: "post_tel",
                            className: 'demo-table-info-column'
                        },
                        {
                            title: "退回物流",
                            key: "logistics_code",
                            className: 'demo-table-info-column'
                        },
                        {
                            title: "状态",
                            key: "order_status_text",
                            className: 'demo-table-info-column'
                        },
                        {
                            title: "处理进度",
                            key:'progress',
                            width:110,
                            className: 'demo-table-info-column',
                            render: (h, params) => {
                                return h('RadioGroup', {
                                        props:{
                                            value: params.row.progress,
                                        },
                                        on: {
                                            'on-change':(event) => {
                                                this.changeValue('progress',params.row,event);
                                            }
                                        },
                                    },
                                    [
                                        h('Radio',{
                                            props: {
                                                label: 1
                                            }
                                        },'平台已退款'),
                                        h('Radio',{
                                            props: {
                                                label: 2
                                            }
                                        },'未处理'),
                                        h('Radio',{
                                            props: {
                                                label: 3
                                            }
                                        },'线下已退款')
                                    ]
                                );
                            },
                        },
                        {
                            title: "登记日期",
                            key: "reg_time",
                            className: 'demo-table-info-column',
                        },
                        {
                            title: "下单时间",
                            key: "create_time",
                            className: 'demo-table-info-column',
                        },
                        {
                            title: "库存",
                            key: "stock",
                            className: 'demo-table-info-column'
                        },
                        {
                            title: "售卖类型",
                            key: "sale_type",
                            className: 'demo-table-info-column'
                        },
                        {
                            title: "操作",
                            key: 'action',
                            width:130,
                            className: 'demo-table-info-column',
                            render: (h, params) => {
                                return h('div', [
                                    h('i-button', {
                                        props: {
                                            type: 'primary',
                                            size: 'small'
                                        },
                                        style: {
                                            marginRight: '5px'
                                        },
                                        on: {
                                            'click': ()=>{
                                                this.saleRegClick(params.row);
                                            }
                                        }
                                    }, "出库"),
                                    h('i-button', {
                                        props: {
                                            type: 'error',
                                            size: 'small'
                                        },
                                        style: {
                                            marginRight: '5px'
                                        },
                                        on: {
                                            'click': ()=>{
                                                this.$Modal.confirm({
                                                    title: '是否要删除订单：'+params.row.order_id+'？',
                                                    onOk:function(){
                                                        vm.del(params.row);
                                                    }
                                                });

                                            }
                                        }
                                    }, "删除")

                                ]);

                            }
                        },

                    ],
                    defaultStartTime:'',
                    defaultEndTime:'',
                    spinShow:false,
                    regModal:false,
                    reg:{
                        order_id:'',
                        reg_person:'庄学能',
                        logistics_code:''
                    },
                    saleModal:false,
                    sale:{
                        sale_type:'公司售卖',
                        order_id:''
                    },
                    search:{
                        phone:'',
                        order_id:'',
                        logistics_code:'',
                        post_receiver:''
                    }

                }
            },
            mounted(){
                this.token = window.localStorage.getItem('current_user');
                this.refundList(1);
                this.$Message.config({
                    top: 90,
                    duration: 3
                });
            },
            methods: {
                searchList(){   //搜索
                    this.refundList(1);
                },
                dateStartFormat(f,v){
                    this.defaultStartTime = f;
                },
                dateEndFormat(f,v){
                    this.defaultEndTime = f;
                },
                refundList(page) {
                    let that = this;
                    this.spinShow = true;
                    axios.get("/admin/order/refund/list",{
                        params: {
                            token:this.token,
                            page: page,
                            phone:this.search.phone,
                            order_id:this.search.order_id,
                            logistics_code:this.search.logistics_code,
                            post_receiver:this.search.post_receiver
                        }
                    })
                    .then(function (response) {
                        vm.tableData = response.data.result.data;
                        vm.page.total   =   response.data.result.total;
                        that.spinShow = false;
                    });
                },
                regClick(){
                    this.regModal = true;
                },
                register(){ //登记
                    this.spinShow = true;
                    axios.post("/admin/order/refund/register",{
                        token:this.token,
                        order_id:this.reg.order_id,
                        logistics_code:this.reg.logistics_code,
                        reg_person:this.reg.reg_person
                    })
                    .then(function (response) {

                        if(response.data.code   ==  400){
                            vm.$Message.error(response.data.msg);
                        }else{
                            vm.$Message.success(response.data.msg);
                        }
                        vm.spinShow = false;
                        vm.refundList(1);
                    });
                },
                saleRegClick(row){ //售卖登记
                    this.saleModal  =   true;
                    this.sale.order_id = row.order_id;
                    if(row.sale_type){
                        this.sale.sale_type = row.sale_type;
                    }
                },
                saleRegister(){ //售卖登记
                    this.spinShow = true;
                    axios.post("/admin/order/refund/sale_reg",{
                        token:this.token,
                        order_id:this.sale.order_id,
                        sale_type:this.sale.sale_type,
                        stock:0
                    })
                    .then(function (response) {

                        if(response.data.code   ==  400){
                            vm.$Message.error(response.data.msg);
                        }else{
                            vm.$Message.success(response.data.msg);
                        }
                        vm.spinShow = false;
                        vm.refundList(1);
                    });
                },
                changeValue(type,row,value){    //修改
                    console.log(value);
                    let order_id    =   row.order_id;

                    let data            =       {};
                    data[type]          =   value;
                    data.token       =   this.token;
                    data.order_id    =   order_id;

                    this.spinShow = true;
                    $.ajax({
                        type:'POST',
                        url :"/admin/order/refund/sale_reg",
                        data:data,
                        success:function(response){
                            if(response.code   ==  400){
                                vm.$Message.error(response.msg);
                            }else{
                                vm.$Message.success(response.msg);
                            }
                            vm.spinShow = false;
                            vm.refundList(1);

                        }
                    })
                },
                del(row){  //delete
                    this.spinShow = true;
                    $.ajax({
                        type:'get',
                        url :"/admin/order/refund/delete",
                        data:{'id':row.id,'token':this.token},
                        success:function(response){
                            if(response.code   ==  400){
                                vm.$Message.error(response.msg);
                            }else{
                                vm.$Message.success(response.msg);
                            }
                            vm.spinShow = false;
                            vm.refundList(1);

                        }
                    })
                }

            },
            computed: {
                combine_link() {
                    return '/admin/order/refund/export?token='+this.token;
                },
                combine_link1() {
                    return '/admin/order/refund/export?type=1&token='+this.token;
                }

            }

        });
        $("body").addClass("sidebar-collapse");
    </script>

@endsection

